import Vue from 'vue';
import iView from 'iview';
import VueRouter from 'vue-router';
import {routers} from "./router.js";
import store from './store/index';
import Vuex from 'vuex';
import App from './app.vue';
import 'iview/dist/styles/iview.css';

Vue.use(VueRouter);
Vue.use(Vuex);
Vue.use(iView);

// 路由配置
const RouterConfig = {
    routes: routers
};

const router = new VueRouter(RouterConfig);

router.beforeEach((r_to, r_from, next) => {
    iView.LoadingBar.start();
    let to = r_to.path;
    let from  = r_from.path;
    if(to === "/"){
        next({path:'/login'})
    }else{
        next()
    }
});

router.afterEach(() => {
    iView.LoadingBar.finish();
    window.scrollTo(0, 0);
});

new Vue({
    el: '#app',
    router: router,
    store: store,
    render: h => h(App)
});
